﻿/*
 * @Author: song
 * @Description:安卓平台构建设置
 * @Date: 2024年04月20日 星期六 12:04:50
 * @Modify:
 */

using UnityEditor;
using UnityEngine.Rendering;

namespace SCore.Editor.BuildPackage.Platform
{
    public class BuildAndroidPlatform : BuildPlatformBase
    {
        public override void SBuild()
        {
            base.SBuild();
            var sBuildChannel = BuildPipelineConfig.Instance._buildChannel;
            //android set
            // GooglePC的话这里需要设置成x86的
            PlayerSettings.Android.targetArchitectures =
                AndroidArchitecture.ARMv7 | AndroidArchitecture.ARM64; //目标CPU平台架构
            PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel23; //最低支持的Andorid API版本
            PlayerSettings.Android.targetSdkVersion = (AndroidSdkVersions)33; //目标API
            PlayerSettings.Android.useAPKExpansionFiles = false; //是否支持OBB文件
            PlayerSettings.Android.disableDepthAndStencilBuffers = false; //默认支持深度和模板缓冲
            PlayerSettings.Android.androidTVCompatibility = false; // 是否兼容Android TV
            PlayerSettings.Android.preferredInstallLocation =
                AndroidPreferredInstallLocation.Auto; //安装位置 自动              
            PlayerSettings.Android.forceInternetPermission = true; //是否强转添加互联网权限
            PlayerSettings.Android.renderOutsideSafeArea = true; //是否接受在安全区(刘海屏挡住的地方)之外的绘制
            // TEST comment
            // 解决黑屏问题 - GraphicsDeviceType.Vulkan?
            PlayerSettings.SetGraphicsAPIs(sBuildChannel.GetBuildTarget(),
                new GraphicsDeviceType[] { GraphicsDeviceType.OpenGLES3 }); //使用的图像API
            //keystore 
            if (string.IsNullOrEmpty(sBuildChannel._keystorePassword))
            {
                PlayerSettings.Android.useCustomKeystore = false;
            }
            else
            {
                PlayerSettings.Android.useCustomKeystore = true;
                PlayerSettings.Android.keystoreName = sBuildChannel._keystoreName;
                PlayerSettings.Android.keystorePass = sBuildChannel._keystorePassword;
                PlayerSettings.Android.keyaliasName = sBuildChannel._keyaliasName;
                PlayerSettings.Android.keyaliasPass = sBuildChannel._keystorePassword;
            }

            PlayerSettings.Android.bundleVersionCode = int.Parse(BuildPipelineConfig.Instance._bundleVersionCode);

            //抄的WOD
            if (BuildPipelineConfig.Instance._release == BuildPipelineUtils.STargetType.Release)
            {
                PlayerSettings.Android.forceSDCardPermission = true;
            }

            if (BuildPipelineConfig.Instance._opExport == BuildPipelineConfig.SBuildOp.Export)
            {
                EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
                EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
                EditorUserBuildSettings.androidCreateSymbolsZip = false;
            }
            else
            {
                EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
                EditorUserBuildSettings.androidCreateSymbolsZip = true;
            }
        }
    }
}